package com.websystique.springsecurity.service;

import com.websystique.springsecurity.dao.SysMenuDao;
import com.websystique.springsecurity.model.SysItem;
import com.websystique.springsecurity.model.SysMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

@Service("sysMenuService")
@Transactional
public class SysMenuServiceImpl implements  SysMenuService {

    @Autowired
    private SysMenuDao sysMenuDao;
    @Override
    public List<SysMenu> findByMenuFatherId(int menuFatherId) {
        return sysMenuDao.findByMenuFatherId(menuFatherId);
    }
   public List<SysMenu> findAll(int menuFatherId) {
        List<SysMenu> list=new ArrayList<>();
        list=sysMenuDao.findByMenuFatherId(menuFatherId);
        if(list.size()>0){
            for(SysMenu sysMenu:list){//遍历一级导航栏
                int fatherid=sysMenu.getMenuId();
                List<SysMenu>list1=sysMenuDao.findByMenuFatherId(fatherid);//查找二级导航
                if(list1.size()>0){
                    List<SysMenu> list2=findAll(fatherid);
                    System.out.println("list2 =="+list2.toString());
                    sysMenu.setList(list2);
                }
            }
        }
        System.out.println("list =="+list.toString());
        return list;
   }
}
